package com.qdlc.p2p.biz.executer.impl;

import java.util.HashMap;
import java.util.Map;

import com.qdlc.p2p.biz.executer.AbstractAccountHandleExecutor;
import com.qdlc.p2p.common.constant.Global;
import com.qdlc.p2p.common.constant.LogTplNid;
import com.qdlc.p2p.common.constant.NoticeTplNid;
import com.qdlc.p2p.dal.common.SystemConfigHelper;
import com.qdlc.p2p.dal.dto.AccountRecharge;
import com.qdlc.p2p.dal.dto.User;
import com.qdlc.p2p.dal.util.SystemConfigs;

/**
 * 用户充值成功，添加资金日志
 */
public class RechargeSuccessExecuter extends AbstractAccountHandleExecutor {
    
	private AccountRecharge recharge;
	
	public RechargeSuccessExecuter() {
		super();
		toUser = new User(SystemConfigs.ADMIN_ID);
	}

	@Override
	public void execute(User user) {
		
		// 处理资金变更
		handleAccount(user);
		
		// 发送短信
		Map<String, Object> templateDataMap = new HashMap<String, Object>();
		templateDataMap.put("recharge", recharge);
		sendNotice(user, NoticeTplNid.RECHARGE_SUCC, templateDataMap);
	}

	@Override
	public void handleAccount(User user) {
		Global.setTransfer(LogTplNid.LOG_TPL_KEY, LogTplNid.RECHARGE_SUCCESS_LOG);
		Global.setTransfer("web_url", SystemConfigHelper.getValue(SystemConfigHelper.Nid.WEB_URL));
		Global.setTransfer("recharge", recharge);
		Global.setTransfer("money", money);
		Global.setTransfer("user", user);
		accountService.addUseMoneyAndTotal(user.getUserId(), toUser.getUserId(), money);
	}

	public void setRecharge(AccountRecharge recharge) {
		this.recharge = recharge;
	}
	
}
